/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package th.quartz;

import com.google.inject.Inject;
import java.text.SimpleDateFormat;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import th.manager.SMSBulkManager;
import java.util.Date;
import java.text.DateFormat;
import java.util.Calendar;
import th.manager.RetrieveSmsInfoManager;

/**
 *
 * @author fikri
 */

public class SmsProcess implements StatefulJob{
    
    @Inject
    private SMSBulkManager manager;
    
    @Inject
    private RetrieveSmsInfoManager infoManager;
    
    private static Logger LOGGER = LoggerFactory.getLogger(SmsProcess.class);
    
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");   
    

    @Override
    public void execute(JobExecutionContext jec) throws JobExecutionException {
        
       String date = getCurrentDate();
       LOGGER.debug("execute : start");
     
       Calendar cal = Calendar.getInstance();
       /**
        * getListOfJemaah by currentDate 
        */
       LOGGER.debug("execute : getListOfJemaah !!");
       if (manager.getListOfJemaah(date)) {
            LOGGER.debug("execute : sms (Jemaah) process starting !!");
            manager.startSmsProcess();
            LOGGER.debug("execute : sms process finished !!");
            LOGGER.debug("execute : sms info starting !!");
            infoManager.doStartRetrieve(cal);
            LOGGER.debug("execute : sms info finished !!");
      }       
       
    }
    
    /**
     * Get current date
     * @return currentDate
     * 
     */
    public String getCurrentDate() {
    
         DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
         Date date = new Date();
         String currentDate = dateFormat.format(date);         
         return currentDate;
    }
}
